/*游戏全局数据*/
AnnieRoot.gameGlobalData = {
	level: 0,
	userCatchedCowSum: 0,//用户套到的牛牛数
	mobileCowCount: 0,//每局手机牛出现的次数计算
	isGameOver: false,
	isThrowing: false,
	isCatching: false,
	initGameData:{time:"20",sum:"9",gamesum:"10"}
};
AnnieRoot.gameFW=AnnieRoot.gameFW||{};
AnnieRoot.gameFW.GameFW=function(){
	var s = this;
	annie.Sprite.call(s);
	/*_a2x_need_start*/s.alertLayer=null;s.gameLayer=null;s.msgLayer=null;s.tipAlertLayer=null;s.uiLayer=null;/*_a2x_need_end*/
	annie.initRes(s,"gameFW","GameFW");
	//your code here
	var gameScene=null,
		gameUi=null,
		gameReadyGo=null,
		gameResult=null,
		gameTip=null,
		gameChooesPrize=null,
		gamePrizeWarmTip=null,
		gameUserMakesureTip=null,
		gameTipAlert=null,
		gameMyPrize=null;
	s.addEventListener(annie.Event.ADD_TO_STAGE, function (e) {
		if (!gameScene) {
			// gameScene = new gscene.Gscene();
			gameScene = annie.getDisplay("gscene","Gscene");
			s.gameLayer.addChild(gameScene);
		}
		if (!gameUi) {
			// gameUi = new ui.Ui();
			gameUi = annie.getDisplay("ui","Ui");
			s.uiLayer.addChild(gameUi);
		}
	});
	annie.globalDispatcher.addEventListener('addGameUiToStage', function (e) {
		if (!gameUi) {
			// gameUi = new ui.Ui();
			gameUi = annie.getDisplay("ui","Ui");
		}
		if (s.uiLayer.children.length == 0) {
			s.uiLayer.addChild(gameUi);
		}
	});
	/*用户游戏次数不够提示*/
	annie.globalDispatcher.addEventListener('userNotEnoughGameTimes', function (e) {
		s.msgLayer.removeChildAt(0);
		if (annie.isLoadedScene('gtip')) {
			if (!gameTip) {
				// gameTip = new gtip.Gtip();
				gameTip = annie.getDisplay("gtip","Gtip");

			}
			s.msgLayer.addChild(gameTip);
		} else {
			annie.loadSceneManager('gtip', s.msgLayer);
		}
	});
	/*游戏321准备*/
	annie.globalDispatcher.addEventListener('readyToGameStart', function (e) {
		if (!gameReadyGo) {
			// gameReadyGo = new readyGo.ReadyGo();
			gameReadyGo = annie.getDisplay("readyGo","ReadyGo");
		}
		gameReadyGo.bringData = 'startGame';
		s.msgLayer.addChild(gameReadyGo);
	});
	/*游戏结果页*/
	annie.globalDispatcher.addEventListener('gameOver', function (e) {
		s.msgLayer.removeChildAt(0);
		if (annie.isLoadedScene('gresult')) {
			if (!gameResult) {
				// gameResult = new gresult.Gresult();
				gameResult = annie.getDisplay("gresult","Gresult");
			}
			gameResult.orderFrom = 'gameOver';
			s.msgLayer.addChild(gameResult);
		} else {
			var orderFrom = 'gameOver';
			annie.loadSceneManager('gresult', s.msgLayer, orderFrom);
		}
	});
	/*添加游戏结果页*/
	annie.globalDispatcher.addEventListener('addGameResultPage', function (e) {
		s.msgLayer.removeChildAt(0);
		if (!gameResult) {
			// gameResult = new gresult.Gresult();
			gameResult = annie.getDisplay("gresult","Gresult");
		}
		gameResult.orderFrom = 'myPrize';
		s.msgLayer.addChild(gameResult);
	});
	/*添加选择奖品页面*/
	annie.globalDispatcher.addEventListener('addChooesGiftBox', function (e) {
		s.msgLayer.removeChildAt(0);
		if (!gameChooesPrize) {
			// gameChooesPrize = new gtip.ChooesPrizeBox();
			gameChooesPrize = annie.getDisplay("gtip","ChooesPrizeBox");

		}
		s.msgLayer.addChild(gameChooesPrize);
	});
	/**/
	annie.globalDispatcher.addEventListener('addWarmTipBox', function (e) {
		s.msgLayer.removeChildAt(0);
		if (!gamePrizeWarmTip) {
			// gamePrizeWarmTip = new gtip.WarmTipBox();
			gamePrizeWarmTip = annie.getDisplay("gtip","WarmTipBox");

		}
		s.msgLayer.addChild(gamePrizeWarmTip);
	});
	/*用选择奖品，提交后提示框*/
	annie.globalDispatcher.addEventListener('addMarkSureTipBox', function (e) {
		s.msgLayer.removeChildAt(0);
		if (!gameUserMakesureTip) {
			// gameUserMakesureTip = new gtip.UserMarkSureBox();
			gameUserMakesureTip = annie.getDisplay("gtip","UserMarkSureBox");

		}
		var bringData = e.data;
		if (bringData) {
			gameUserMakesureTip.bringData = bringData;
		}
		s.msgLayer.addChild(gameUserMakesureTip);
	});
	/*我的奖品页*/
	annie.globalDispatcher.addEventListener('addMyPrizePage', function (e) {
		if (annie.isLoadedScene('gmyprize')) {
			if (!gameMyPrize) {
				gameMyPrize =  annie.getDisplay("gmyprize","Gmyprize").Gmyprize();
			}
			s.msgLayer.addChild(gameMyPrize);
		} else {
			annie.loadSceneManager('gmyprize', s.msgLayer);
		}
	});
	/*套绳子结束321倒数准备时间*/
	annie.globalDispatcher.addEventListener('readyTime', function (e) {
		// s.msgLayer.removeChildAt(0);
		// if (!gameReadyGo) {
		// 	gameReadyGo = new readyGo.ReadyGo();
		// }
		gameReadyGo.bringData = 'gaming';
		annie.globalDispatcher.dispatchEvent('userAbleToPlayGame');//用户可以继续点击套牛按钮了
		// s.msgLayer.addChild(gameReadyGo);
	});
	annie.globalDispatcher.addEventListener('addTipAlert', function (e) {
		s.tipAlertLayer.removeChildAt(0);
		if (!gameTipAlert) {
			// gameTipAlert = new gtipAlert.GtipAlert();
			gameTipAlert =  annie.getDisplay("gtipAlert","GtipAlert").Gmyprize();

		}
		gameTipAlert.tip_txt.text = e.data;
		s.tipAlertLayer.addChild(gameTipAlert);
	});
	// tipAlertLayer
};
annie.A2xExtend(AnnieRoot.gameFW.GameFW,annie.Sprite);
